#pragma once
#include "DCore.h"

class Board
{	
public:
	enum BOARD_ATTRIBUTE
	{
		ATTR_SHOW		= 0x01,
		ATTR_MOVEABLE	= 0x02,
		ATTR_ALL		= 0x03
	};
	enum BOARD_TYPE
	{
		TYPE_STAGE,
		TYPE_SCENE,
		TYPE_CONTROL
	};
	enum EDIT_TYPE
	{
		EDIT_POS	 = -1,
		EDIT_SIZE	 = 1
	};
	
	enum BOARD_STATE
	{
		STATE_NORMAL,
		STATE_DISABLED,
		STATE_HIGHLIGHT,
		STATE_PUSHED,
	};

private:
	LPDIRECT3DVERTEXBUFFER9		m_pVB;
	LPDIRECT3DDEVICE9			m_pDevice;

	DVertex m_SurfaceVertex[4];

protected:

	Board*	m_pParentBoard;
	int		m_LoadTextureIndex;
	int		m_boardState;

	DWORD	m_attribute;

	bool	m_CursorInBoard;
	bool	m_ActiveBoard;

	DInput* m_pInput;
	int		m_boardType;

	float	m_posX;
	float	m_posY;
	float	m_width;
	float	m_height;
	float	m_centerX;
	float	m_centerY;

	
	float	m_startU;
	float	m_startV;
	float	m_endU;
	float	m_endV;

	float	m_capturedCursorPosX;
	float	m_capturedCursorPosY;

	RECT	m_boardRect;

	static int		m_editType;
	
	static Board* m_pFocusBoard;
	static Board* m_pCapturedBoard;
	//static Board* m_pFrameViewBoard;

public:
	std::list<Board*>			m_ChildBoardList;
	std::map<int,DTexture*>		m_TextureMap;


public:
	virtual bool Init();
	virtual bool Frame();
	virtual bool Render();
	virtual bool Release();

	virtual void InputProcess();

	void Run();


	void InitVertexBuffer();

	void FrameSurfaceVertex();
	void FrameVertexBuffer();

	void AddChildWindow( Board* pBoard );
	void RemoveChildWindow( Board* pBoard );

	inline float GetBoardPosX()				const { return m_posX; }
	inline float GetBoardPosY()				const { return m_posY; }
	inline float GetBoardWidth()			const { return m_width; }
	inline float GetBoardHeight()			const { return m_height; }
	inline float GetBoardCenterX()			const { return m_centerX; }
	inline float GetBoardCenterY()			const { return m_centerY; }
	inline RECT GetBoardRECT()				const { return m_boardRect; }
	inline int GetBoardType()				const { return m_boardType; }

	inline float GetCapturedCursorPosX()			const { return m_capturedCursorPosX; }
	inline float GetCapturedCursorPosY()			const { return m_capturedCursorPosY; }
	inline TCHAR* GetTexturePathName(int state)		 { return m_TextureMap[state]->GetFilePath(); }

	inline Board* GetFocusBoard()			const { return m_pFocusBoard; }
	inline Board* GetCapturedBoard()		const { return m_pCapturedBoard; }
	//inline Board* GetFrameViewBoard()	const { return m_pFrameViewBoard; }

	inline bool IsMoveable()			{ return (m_attribute & ATTR_MOVEABLE) == ATTR_MOVEABLE ? true : false; }

	inline void SetBoardPos(float x, float y)				{ m_posX = x; m_posY = y; }
	inline void SetBoardSize(float width, float height)		{ m_width = width; m_height = height; }
	inline void SetBoardType(int boardType)					{ m_boardType = boardType; }

	inline void SetCapturedCursorPos(float x, float y)	{ m_capturedCursorPosX = x; m_capturedCursorPosY = y; }
	inline void SetStartUV(float u, float v)			{ m_startU = u; m_startV = v; }
	inline void SetEndUV(float u, float v)				{ m_endU = u; m_endV = v; }

	inline void SetBoardAttribute( DWORD attribute )	{ m_attribute = attribute; }
	inline void SetParentBoard(Board* pBoard)			{ m_pParentBoard = pBoard; }
	inline void SetActiveBoard(bool active)				{ m_ActiveBoard = active; }

	inline void SetFocusBoard()							{ m_pFocusBoard = this; }
	inline void SetCaptureBoard()						{ m_pCapturedBoard = this; }

	inline void ReleaseCaptureBoard()					{ m_pCapturedBoard = 0; }

	void Undo();

public:
	Board(void);
	~Board(void);
};

class Work
{
protected:
	float m_x;
	float m_y;
	Work* m_Prev;
	Board* m_pBoard;
public:
	inline void SetPrev(Work* pPrev)		{ m_Prev = pPrev;	}
	inline Work* GetPrev()					{ return m_Prev;	}

	virtual void Do(Board* pBoard, float x,float y) = 0;
	virtual void Undo() = 0;
public:
	Work(void) {}
	virtual ~Work(void) {}
};


class MoveWork : public Work
{
public:
	void Do(Board* pBoard, float x,float y);
	void Undo();
public:
	MoveWork(void) {}
	virtual ~MoveWork(void) {}
};

class SceneMoveWork : public Work
{
public:
	void Do(Board* pBoard, float x,float y);
	void Undo();
public:
	SceneMoveWork(void) {}
	virtual ~SceneMoveWork(void) {}
};
